package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MovieDetailActivity extends AppCompatActivity {

    private TextView titleTextView;
    private TextView descriptionTextView;
    private ImageView imageView;
    private Button selectButton;

    private String movieTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie_detail);

        // 获取传递的电影数据
        Intent intent = getIntent();
        movieTitle = intent.getStringExtra("movie_title");
        String movieDescription = intent.getStringExtra("movie_description");
        int imageResourceId = intent.getIntExtra("movie_image", 0);

        // 初始化视图
        titleTextView = findViewById(R.id.text_name);
        descriptionTextView = findViewById(R.id.text_brief);
        imageView = findViewById(R.id.img_imgId);
        selectButton = findViewById(R.id.select_button);

        // 设置电影数据
        titleTextView.setText(movieTitle);
        descriptionTextView.setText(movieDescription);
        imageView.setImageResource(imageResourceId);

        // 设置选择按钮点击事件
        selectButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 返回选中的电影名称
                Intent resultIntent = new Intent();
                resultIntent.putExtra("selected_movie", movieTitle);
                setResult(RESULT_OK, resultIntent);
                finish();
            }
        });
    }
}    